package com.simpd.db_helper;

import java.util.ArrayList;

import com.simpd.model.NotifikasiSKPD;
import com.simpd.model.ServerSimpd;
import com.simpd.model.SessionSimpd;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper{
	
	// Logcat tag 
	// private static final String LOG = "[databaseHelper]"; 
	
	// Database version 
	public static final int VERSION  =  3;
	
	// Database name
	private static final String DATABASE_NAME 	 = "db_simpd";
	
	// Table names 
	private static final String TABLE_NOTIFIKASI = "notifikasi";
	private static final String TABLE_SESSION	 = "session";
	private static final String TABLE_SERVER 	 = "server";
	// Common column names
	public static final String KEY_ID = "id";
	
	// Notifikasi Table - column names 
	public static final String KEY_SKPD 			= "skpd"; 
	public static final String KEY_TANGGAL_UPDATE 	= "tanggal_update_status"; 
	public static final String KEY_PERIHAL 			= "perihal";
	public static final String KEY_TIPE_SURAT 		= "tipe_surat";
	public static final String KEY_ONLINE_URL		= "online_url";
	public static final String KEY_STATUS 			= "status";
	public static final String KEY_OFFLINE_URL		= "offline_url";
	public static final String KEY_SEBAGAI			= "sebagai";
	public static final String KEY_KETERANGAN		= "keterangan";
	// Default values
	
	// Session Table - column names 
	public static final String KEY_UNIP 			= "unip";
	public static final String KEY_TOKEN			= "token"; 
	
	// Server Table - column names
	public static final String KEY_SERVER_URL		= "server_url";
	
	public static final int DEFAULT_STATUS 			= 0;
	public static final String DEFAULT_OFFLINE_URL	= "";
	public static final String DEFAULT_KETERANGAN 	= "";
	
	private static final String[] TABLE_NOTIFIKASI_COLUMNS = {KEY_ID, KEY_SKPD, KEY_TANGGAL_UPDATE, 
															  KEY_PERIHAL, KEY_TIPE_SURAT, 
															  KEY_ONLINE_URL, KEY_OFFLINE_URL, KEY_SEBAGAI, 
															  KEY_STATUS, KEY_KETERANGAN};
	
	private static final String[] TABLE_SESSION_COLUMNS	   = {KEY_ID, KEY_UNIP, KEY_TOKEN};
	
	
	private static final String[] TABLE_SERVER_COLUMNS = {KEY_ID, KEY_SERVER_URL};
	// Notifikasi table create statement
	public static final String CREATE_TABLE_NOTIFIKASI = "CREATE TABLE " + TABLE_NOTIFIKASI+
							   							 " (" + KEY_ID + " INTEGER PRIMARY KEY, "
							   							 	  + KEY_SKPD + " TEXT, " 
							   							 	  + KEY_TANGGAL_UPDATE + " DATETIME, " 
							   							 	  + KEY_PERIHAL + " TEXT, " 
							   							 	  + KEY_TIPE_SURAT + " TEXT, " 
							   							 	  +	KEY_ONLINE_URL	+" TEXT, "
							   							 	  +	KEY_OFFLINE_URL	+" TEXT, " 
							   							 	  + KEY_SEBAGAI + " TEXT, "
							   							 	  + KEY_STATUS + " INTEGER, " 
							   							 	  + KEY_KETERANGAN + " TEXT)";
	
	public static final String CREATE_TABLE_SESSION 	= "CREATE TABLE "+ TABLE_SESSION +
														  " (" + KEY_ID + " INTEGER PRIMARY KEY, "
															   + KEY_UNIP + " TEXT, "
														  	   + KEY_TOKEN + " TEXT)";
	
	public static final String CREATE_TABLE_SERVER		= "CREATE TABLE "+ TABLE_SERVER + 
														  " (" + KEY_ID+ " INTEGER PRIMARY KEY, "
														  	   + KEY_SERVER_URL + " TEXT)";
	
	
	// Constant status notifications
	public static final int STATUS_NOT_READ = 0; 
	public static final int STATUS_READ = 1; 
	public static final int STATUS_SIGNATURE = 2;
	
	
	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, VERSION);
		
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// Create required table 
		db.execSQL(CREATE_TABLE_NOTIFIKASI);
		db.execSQL(CREATE_TABLE_SESSION);
		db.execSQL(CREATE_TABLE_SERVER);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// on upgrade drop older table first
		db.execSQL("DROP TABLE IF EXISTS "+ TABLE_NOTIFIKASI); 
		db.execSQL("DROP TABLE IF EXISTS "+ TABLE_SESSION);
		db.execSQL("DROP TABLE IF EXISTS "+ TABLE_SERVER);
		// Create new table 
		onCreate(db);
	}
	
	/**
	 * 
	 * @param notifikasi
	 * @return id from inserted 
	 */
	
	public long insertNotifikasi(NotifikasiSKPD notifikasi){
		SQLiteDatabase db = this.getWritableDatabase(); 
		
		ContentValues values = new ContentValues(); 
		values.put(KEY_SKPD, notifikasi.getSkpd()); 
		values.put(KEY_TANGGAL_UPDATE, notifikasi.getTanggalUpdate());
		values.put(KEY_PERIHAL, notifikasi.getPerihal());
		values.put(KEY_TIPE_SURAT, notifikasi.getTipeSurat());
		values.put(KEY_ONLINE_URL, notifikasi.getOnlineUrl());
		values.put(KEY_OFFLINE_URL, notifikasi.getOfflineUrl());
		values.put(KEY_SEBAGAI, notifikasi.getSebagai());
		values.put(KEY_STATUS, notifikasi.getStatus());
		values.put(KEY_KETERANGAN, notifikasi.getKeterangan());
		long inserted_id = db.insert(TABLE_NOTIFIKASI, null, values);
		
		db.close();
		return inserted_id;
	}
	
	/**
	 * 
	 * @param skpd
	 * @param tanggalUpdate
	 * @param perihal
	 * @param tipeSurat
	 * @return id from inserted data
	 */
	public long insertNotifikasi(String skpd, String tanggalUpdate, String perihal, String tipeSurat, String url){
		SQLiteDatabase db = this.getWritableDatabase(); 
		
		ContentValues values = new ContentValues(); 
		values.put(KEY_SKPD, skpd); 
		values.put(KEY_TANGGAL_UPDATE, tanggalUpdate); 
		values.put(KEY_PERIHAL, perihal); 
		values.put(KEY_TIPE_SURAT, tipeSurat);
		values.put(KEY_ONLINE_URL,  url);
		values.put(KEY_OFFLINE_URL, DEFAULT_OFFLINE_URL);
		values.put(KEY_SEBAGAI, ""); // belum
		values.put(KEY_STATUS, DEFAULT_STATUS);
		values.put(KEY_KETERANGAN, DEFAULT_KETERANGAN);
		
		long inserted_id = db.insert(TABLE_NOTIFIKASI, null, values);
		db.close();
		return inserted_id;
	
	}
	
	/**
	 * 
	 * @param id
	 * @return NotifikasiSKPD object that has id values 
	 * equals as parameter value
	 */
	
	public NotifikasiSKPD getNotifikasi(long id){
		SQLiteDatabase db = this.getReadableDatabase();
		
		NotifikasiSKPD notifikasi = null;
		
		Cursor cursor = db.query(TABLE_NOTIFIKASI, TABLE_NOTIFIKASI_COLUMNS, KEY_ID+" = ? ", 
						   new String[]{String.valueOf(id)}, null, null, null);
		if (cursor.moveToFirst()) {
			notifikasi = new NotifikasiSKPD(); 
			notifikasi.setId(cursor.getInt(0));
			notifikasi.setSkpd(cursor.getString(1)); 
			notifikasi.setTanggalUpdate(cursor.getString(2)); 
			notifikasi.setPerihal(cursor.getString(3)); 
			notifikasi.setTipeSurat(cursor.getString(4));
			notifikasi.setOnlineUrl(cursor.getString(5));
			notifikasi.setOfflineUrl(cursor.getString(6));
			notifikasi.setSebagai(cursor.getString(7));
			notifikasi.setStatus(cursor.getInt(8));
			notifikasi.setKeterangan(cursor.getString(9));
		}
		/* 	 index key :
		 * 0 KEY_ID, 
		 * 1 KEY_SKPD, 
		 * 2 KEY_TANGGAL_UPDATE,
		 * 3 KEY_PERIHAL, 
		 * 4 KEY_TIPE_SURAT, 
		 * 5 KEY_ONLINE_URL, 
		 * 6 KEY_OFFLINE_URL,
		 * 7 KEY_SEBAGAI,
		 * 8 KEY_STATUS,
		 * 9 KEY_KETERANGAN};*/
		db.close();
		return notifikasi;
	}
	
	/**
	 * 
	 * @return arraylis<NotifikasiSKPD>
	 * get all Notifikasi data from database 
	 */
	public ArrayList<NotifikasiSKPD> getAllNotifikasi(){
		ArrayList<NotifikasiSKPD> allNotifikasi = new ArrayList<NotifikasiSKPD>(); 
		NotifikasiSKPD notifikasi = null;
		SQLiteDatabase db = this.getReadableDatabase(); 
		
		Cursor cursor = db.query(TABLE_NOTIFIKASI, TABLE_NOTIFIKASI_COLUMNS, null, null, null, null, null);
		
		if(cursor.moveToFirst()){
			do {
				notifikasi = new NotifikasiSKPD(); 
				notifikasi.setId(cursor.getInt(0));
				notifikasi.setSkpd(cursor.getString(1)); 
				notifikasi.setTanggalUpdate(cursor.getString(2)); 
				notifikasi.setPerihal(cursor.getString(3)); 
				notifikasi.setTipeSurat(cursor.getString(4));
				notifikasi.setOnlineUrl(cursor.getString(5));
				notifikasi.setOfflineUrl(cursor.getString(6));
				notifikasi.setSebagai(cursor.getString(7));
				notifikasi.setStatus(cursor.getInt(8));
				notifikasi.setKeterangan(cursor.getString(9));
				
				allNotifikasi.add(notifikasi);
			} while (cursor.moveToNext());
		}
		db.close();
		return allNotifikasi;
		/* 	 index key :
		 * 0 KEY_ID, 
		 * 1 KEY_SKPD, 
		 * 2 KEY_TANGGAL_UPDATE,
		 * 3 KEY_PERIHAL, 
		 * 4 KEY_TIPE_SURAT, 
		 * 5 KEY_ONLINE_URL, 
		 * 6 KEY_OFFLINE_URL,
		 * 7 KEY_SEBAGAI,
		 * 8 KEY_STATUS, 
		 * 9 KEY_KETERANGAN};*/
		
	}
	
	/**
	 * 
	 * @param orderBy
	 * @param isAscending
	 * @return arraylis of notifikasi
	 * used to filtering notification by ordering particular column with ASC or DESC function.
	 */
	public ArrayList<NotifikasiSKPD> getAllNotifikasi(String orderBy, boolean isAscending){
		ArrayList<NotifikasiSKPD> allNotifikasi = new ArrayList<NotifikasiSKPD>(); 
		NotifikasiSKPD notifikasi = null;
		SQLiteDatabase db = this.getReadableDatabase(); 
		
		String orderType = "ASC";
		if(isAscending == false){
			orderType = "DESC";
		}
	
		Cursor cursor = db.query(TABLE_NOTIFIKASI, TABLE_NOTIFIKASI_COLUMNS, null, null, null, null, orderBy+ " "+orderType);
		
		if(cursor.moveToFirst()){
			do {
				notifikasi = new NotifikasiSKPD(); 
				notifikasi.setId(cursor.getInt(0));
				notifikasi.setSkpd(cursor.getString(1)); 
				notifikasi.setTanggalUpdate(cursor.getString(2)); 
				notifikasi.setPerihal(cursor.getString(3)); 
				notifikasi.setTipeSurat(cursor.getString(4));
				notifikasi.setOnlineUrl(cursor.getString(5));
				notifikasi.setOfflineUrl(cursor.getString(6));
				notifikasi.setSebagai(cursor.getString(7));
				notifikasi.setStatus(cursor.getInt(8));
				notifikasi.setKeterangan(cursor.getString(9));
				
				allNotifikasi.add(notifikasi);
			} while (cursor.moveToNext());
		}
		db.close();
		return allNotifikasi;
		
	}
	
	public ArrayList<NotifikasiSKPD> getAllNotifikasiWhere(String selection, String[] selectionArgs){
		ArrayList<NotifikasiSKPD> allNotifikasi = new ArrayList<NotifikasiSKPD>(); 
		NotifikasiSKPD notifikasi = null;
		SQLiteDatabase db = this.getReadableDatabase(); 
		
		String orderby = KEY_TANGGAL_UPDATE;
		boolean isAscending = false;
		
		String orderType = "ASC";
		if(isAscending == false){
			orderType = "DESC";
		}
		
		Cursor cursor = db.query(TABLE_NOTIFIKASI, TABLE_NOTIFIKASI_COLUMNS, selection, selectionArgs, null, null, orderby+" "+orderType);
		
		/* 	 index key :
		 * 0 KEY_ID, 
		 * 1 KEY_SKPD, 
		 * 2 KEY_TANGGAL_UPDATE,
		 * 3 KEY_PERIHAL, 
		 * 4 KEY_TIPE_SURAT, 
		 * 5 KEY_ONLINE_URL, 
		 * 6 KEY_OFFLINE_URL,
		 * 7 KEY_SEBAGAI,
		 * 8 KEY_STATUS, 
		 * 9 KEY_KETERANGAN};*/
		if(cursor.moveToFirst()){
			do {
				notifikasi = new NotifikasiSKPD(); 
				notifikasi.setId(cursor.getInt(0));
				notifikasi.setSkpd(cursor.getString(1)); 
				notifikasi.setTanggalUpdate(cursor.getString(2)); 
				notifikasi.setPerihal(cursor.getString(3)); 
				notifikasi.setTipeSurat(cursor.getString(4));
				notifikasi.setOnlineUrl(cursor.getString(5));
				notifikasi.setOfflineUrl(cursor.getString(6));
				notifikasi.setSebagai(cursor.getString(7));
				notifikasi.setStatus(cursor.getInt(8));
				notifikasi.setKeterangan(cursor.getString(9));
				allNotifikasi.add(notifikasi);
			} while (cursor.moveToNext());
		}
		db.close();
		return allNotifikasi;
		
	}
	/**
	 * 
	 * @return arraylist of String that contains unique value of skpd
	 */
	public ArrayList<String> getDistinctSkpd(){
		SQLiteDatabase db = this.getReadableDatabase();
		ArrayList<String> results = new ArrayList<String>();
		String result = null;
		Cursor cursor = db.query(true, TABLE_NOTIFIKASI, new String[]{KEY_SKPD}, 
								 null, null, null, null, null, null);
		if(cursor.moveToFirst()){
			do {
				result = cursor.getString(0);
				results.add(result);
			} while (cursor.moveToNext());
		}
		db.close();
		return results;
	}
	
	
	/**
	 * 
	 * @return last notifikasi skpd
	 */
	public NotifikasiSKPD getLastNotifikasi(){
		SQLiteDatabase db = this.getReadableDatabase();
		String query = "SELECT * FROM "+TABLE_NOTIFIKASI+" ORDER BY "+KEY_TANGGAL_UPDATE+" DESC LIMIT 1";
		NotifikasiSKPD notifikasi = null;
		Cursor cursor = db.rawQuery(query, null);
		/* 	 index key :
		 * 0 KEY_ID, 
		 * 1 KEY_SKPD, 
		 * 2 KEY_TANGGAL_UPDATE,
		 * 3 KEY_PERIHAL, 
		 * 4 KEY_TIPE_SURAT, 
		 * 5 KEY_ONLINE_URL, 
		 * 6 KEY_OFFLINE_URL,
		 * 7 KEY_SEBAGAI,
		 * 8 KEY_STATUS, 
		 * 9 KEY_KETERANGAN};*/
		if(cursor.moveToFirst()){
			notifikasi = new NotifikasiSKPD();
			notifikasi.setId(cursor.getInt(0));
			notifikasi.setSkpd(cursor.getString(1)); 
			notifikasi.setTanggalUpdate(cursor.getString(2)); 
			notifikasi.setPerihal(cursor.getString(3));
			notifikasi.setTipeSurat(cursor.getString(4));
			notifikasi.setOnlineUrl(cursor.getString(5));
			notifikasi.setOfflineUrl(cursor.getString(6));
			notifikasi.setSebagai(cursor.getString(7));
			notifikasi.setStatus(cursor.getInt(8));
			notifikasi.setKeterangan(cursor.getString(9));
		}
		db.close();
		return notifikasi;
	}
	
	/**
	 * 
	 * @param skpd
	 * @return arraylist of notifikasi group by skpd
	 */
	public ArrayList<NotifikasiSKPD> getNotifikasiBySkpd(String skpd){
		SQLiteDatabase db = this.getReadableDatabase(); 
		ArrayList<NotifikasiSKPD> results = new ArrayList<NotifikasiSKPD>();
		NotifikasiSKPD notifikasi = null; 
		
		Cursor cursor = db.query(TABLE_NOTIFIKASI, TABLE_NOTIFIKASI_COLUMNS, KEY_SKPD+" = ? ", 
								 new String[]{skpd}, null, null, null);
		
		/* 	 index key :
		 * 0 KEY_ID, 
		 * 1 KEY_SKPD, 
		 * 2 KEY_TANGGAL_UPDATE,
		 * 3 KEY_PERIHAL, 
		 * 4 KEY_TIPE_SURAT, 
		 * 5 KEY_ONLINE_URL, 
		 * 6 KEY_OFFLINE_URL,
		 * 7 KEY_STATUS};*/
		if(cursor.moveToFirst()){
			do {
				notifikasi = new NotifikasiSKPD(); 
				notifikasi.setId(cursor.getInt(0)); 
				notifikasi.setSkpd(cursor.getString(1));
				notifikasi.setTanggalUpdate(cursor.getString(2));
				notifikasi.setPerihal(cursor.getString(3)); 
				notifikasi.setTipeSurat(cursor.getString(4));
				notifikasi.setOnlineUrl(cursor.getString(5));
				notifikasi.setOfflineUrl(cursor.getString(6));
				notifikasi.setSebagai(cursor.getString(7));
				notifikasi.setStatus(cursor.getInt(8));
				notifikasi.setKeterangan(cursor.getString(9));
				
				results.add(notifikasi);
			} while (cursor.moveToNext());
		}
		
		db.close();
		return results;
	}
	
	/**
	 * 
	 * @param id
	 * @param notifikasi
	 * @return number of affected rows
	 */
	public long update(long id, NotifikasiSKPD notifikasi){
		SQLiteDatabase db = this.getWritableDatabase(); 
		ContentValues values = new ContentValues();
		values.put(KEY_SKPD, notifikasi.getSkpd());
		values.put(KEY_TANGGAL_UPDATE, notifikasi.getTanggalUpdate()); 
		values.put(KEY_PERIHAL, notifikasi.getPerihal()); 
		values.put(KEY_TIPE_SURAT, notifikasi.getTipeSurat());
		values.put(KEY_ONLINE_URL, notifikasi.getOnlineUrl());
		values.put(KEY_OFFLINE_URL, notifikasi.getOfflineUrl());
		values.put(KEY_SEBAGAI, notifikasi.getSebagai());
		values.put(KEY_STATUS, notifikasi.getStatus());
		values.put(KEY_KETERANGAN, notifikasi.getKeterangan());
		int affectedRows = db.update(TABLE_NOTIFIKASI, values, KEY_ID +" = ? ", new String[]{String.valueOf(id)});
		db.close();
		return affectedRows;
	}
	
	/**
	 * @param id, id record want to delete 
	 * return number of affected rows
	 */
	public long deleteNotifikasi(long id){
		SQLiteDatabase db = this.getWritableDatabase();
		
		long affected_rows = db.delete(TABLE_NOTIFIKASI, KEY_ID +" = ? ", new String[]{String.valueOf(id)});
		db.close();
		return affected_rows;
	}
	
	/**
	 * 
	 * @return number of affected rows when all notifikasi data delete
	 */
	public long deleteAllNotifikasi(){
		SQLiteDatabase db = this.getWritableDatabase(); 
		long affected_rows = db.delete(TABLE_NOTIFIKASI, null, null);
		db.close(); 
		return affected_rows;
	}
	
	public long insertSession(SessionSimpd session){
		SQLiteDatabase db = this.getWritableDatabase(); 
		ContentValues values = new ContentValues(); 
		values.put(KEY_UNIP, session.getUnip());
		values.put(KEY_TOKEN, session.getToken());
		
		long insertedId = db.insert(TABLE_SESSION, null, values); 
		db.close(); 
		return insertedId; 
	}
	
	public long insertSession(String unip, String token){
		SQLiteDatabase db = this.getWritableDatabase(); 
		ContentValues values = new ContentValues(); 
		values.put(KEY_UNIP, unip);
		values.put(KEY_TOKEN, token); 
		
		long insertedId = db.insert(TABLE_SESSION, null, values);
		db.close();
		return insertedId;
	}
	
	public long updateSession(SessionSimpd session){
		SQLiteDatabase db = this.getWritableDatabase(); 
		ContentValues values = new ContentValues(); 
		values.put(KEY_UNIP, session.getUnip()); 
		values.put(KEY_TOKEN, session.getToken());
		
		long affectedRows = db.update(TABLE_SESSION, values, KEY_ID+" = ?", 
									  new String[]{String.valueOf(session.getId())});
		db.close(); 
		return affectedRows;
	}
	
	public SessionSimpd getSession(){
		SQLiteDatabase db = this.getReadableDatabase(); 
		Cursor cursor = db.query(TABLE_SESSION, TABLE_SESSION_COLUMNS, null, null, null, null, null);
		SessionSimpd session = null;
		if(cursor.moveToFirst()){
			session = new SessionSimpd();
			session.setId(cursor.getInt(0));
			session.setUnip(cursor.getString(1)); 
			session.setToken(cursor.getString(2));
		}
		db.close();
		return session;
	}
	
	public long resetSession(SessionSimpd session){
		SQLiteDatabase db = this.getWritableDatabase(); 
		ContentValues values = new ContentValues(); 
		values.put(KEY_TOKEN, "logout"); 
		long affectedRows = db.update(TABLE_SESSION, values, KEY_ID+" = ?", 
									  new String[] {String.valueOf(session.getId())});
		db.close();
		return affectedRows;
	}
	
	public long deleteSession(){
		SQLiteDatabase db = this.getWritableDatabase();
		long affectedRows = db.delete(TABLE_SESSION, null, null); 
		db.close();
		return affectedRows;
	}
	
	public long insertServer(String serverUrl){
		SQLiteDatabase db = this.getWritableDatabase();
		ContentValues values = new ContentValues(); 
		values.put(KEY_SERVER_URL, serverUrl);
		long insertedId = db.insert(TABLE_SERVER, null, values);
		db.close();
		return insertedId;
	}
	
	public long insertServer(ServerSimpd server){
		SQLiteDatabase db = this.getWritableDatabase(); 
		ContentValues values = new ContentValues(); 
		values.put(KEY_SERVER_URL, server.getServerUrl());
		long insertedId = db.insert(TABLE_SERVER, null, values);
		db.close();
		return insertedId;
	}
	
	
	public ServerSimpd getServer(){
		SQLiteDatabase db = this.getReadableDatabase(); 
		ServerSimpd server = null;
		Cursor cursor = db.query(TABLE_SERVER, TABLE_SERVER_COLUMNS, null, null, null, null, null);
		
		if(cursor.moveToFirst()){
			server = new ServerSimpd(); 
			server.setId(cursor.getInt(0));
			server.setServerUrl(cursor.getString(1));
		}
		db.close();
		return server;
	}
	
	public long updateServer(ServerSimpd server){
		SQLiteDatabase db = this.getWritableDatabase(); 
		ContentValues values = new ContentValues();
		values.put(KEY_SERVER_URL, server.getServerUrl());
		long affectedRows = db.update(TABLE_SERVER, values, KEY_ID+" = ? ", 
								new String[] {String.valueOf(server.getId())});
		db.close();
		return affectedRows;
	}
	
	public long deleteServer(int id){
		SQLiteDatabase db = this.getWritableDatabase(); 
		long affectedRows = db.delete(TABLE_SERVER, KEY_ID+" = ? ", new String[]{String.valueOf(id)});
		db.close();
		return affectedRows;
	}
	
	/**
	 * drop table notifikasi and re-create it again
	 * use when there is changes of table column
	 */
	public void dropTable(){
		SQLiteDatabase db = this.getWritableDatabase(); 
		db.execSQL("DROP TABLE IF EXISTS "+TABLE_NOTIFIKASI); 
		db.execSQL("DROP TABLE IF EXISTS "+TABLE_SESSION);
		db.execSQL("DROP TABLE IF EXISTS "+TABLE_SERVER);
		onCreate(db);
		db.close();
	}
	
	
}



















